package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")

public class SpuManageController {

    @Autowired
    private ManageService manageService;



    @GetMapping("/{page}/{limit}")
    public Result getSpuInfoPage(@PathVariable Long page,
                                 @PathVariable Long limit,
                                 SpuInfo spuInfo){
        Page<SpuInfo> spuInfoPage = new Page<>(page,limit);

        IPage<SpuInfo> spuInfoPageList = manageService.getSupInfoPage(spuInfoPage,spuInfo);
        return Result.ok(spuInfoPageList);
    }

    @GetMapping("/baseSaleAttrList")
    public Result getBaseSaleAttrList() {
        List<BaseSaleAttr> baseSaleAttrList = manageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
    @GetMapping("getSpuInfo/{id}")
    public Result getSpuInfo(@PathVariable Long id){
        SpuInfo spuInfo = manageService.getSupInfo(id);
        return Result.ok(spuInfo);
    }
    @PostMapping("updateSpuInfo")
    public Result updateSpuInfo(@RequestBody SpuInfo spuInfo) {
        manageService.updateSpuInfo(spuInfo);
        return Result.ok();
    }

}
